package com.trafficradio.trafficradio;

import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.trafficradio.trafficradio.network.LocationUpdate;
import com.trafficradio.trafficradio.operation.Operation;
import com.trafficradio.trafficradio.util.Data;
import com.trafficradio.trafficradio.util.MyHandler;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    Operation operation;
    private MyHandler handler;
    TextView text[];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler = new MyHandler(this);
        operation = new Operation(handler);
        setContentView(R.layout.activity_main);
        Data.setUsername("b");
        LocationUpdate l = new LocationUpdate(this);
        text = new TextView[3];


    }
    public void g(View v) {
        //operation.loadText();
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.setType("*/*");
        i.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(i,1);




    }
    @Override
    protected void onActivityResult(int requestCode,int resultCode,Intent data){

            if(resultCode == RESULT_OK){
                Uri uri = data.getData();
                ContentResolver resolver = getContentResolver();
                Cursor cursor = resolver.query(uri,
                        new String[]{MediaStore.Images.Media.DATA},null,null,null);
                cursor.moveToFirst();
                String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
                File f = new File(path);

                operation.updateFile(f);
            }

    }
    public void f(View v){
    //Toast.makeText(this,,Toast.LENGTH_SHORT).show();
//        for (int i = 0;i<3;i++){
//            text[i] = new TextView(this);
//            text[i].setText(Data.text[i]);
//            LinearLayout l = (LinearLayout)findViewById(R.id.mylayout);
//            l.addView(text[i]);
//
//        }
    }

}
